const { DataTypes } = require("sequelize");

const seq = require("../db/seq");

//! 创建模型 ( Model sh_topic --> sh_topics ) 默认会添加s
const Topic = seq.define(
  "sh_topic",
  {
    //? id字段自增，所以会被sequelize自动维护

    topic_user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "发布帖子用户的id",
    },
    topic_user_name: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: false,
      comment: "发布帖子的用户名",
    },
    topic_user_avatar: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "http://82.157.94.91:8000/defaultAvatar.jpg",
      comment: "发布帖子的用户头像",
    },

    topic_type: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: false,
      comment: "帖子类型",
    },
    topic_title: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: false,
      comment: "帖子标题",
    },
    topic_content: {
      type: DataTypes.STRING(10240),
      allowNull: true,
      unique: false,
      comment: "帖子正文",
    },
    topic_img: {
      type: DataTypes.STRING,
      allowNull: true,
      unique: false,
      comment: "帖子图片地址",
    },
    topic_number_of_likes: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: "帖子的点赞数",
    },
  },
  {
    tableName: "sh_topics", //todo 直接提供表名
    //* timestamps: false,  //?让seq不会自动创建createdAt 和 updatedAt
  }
);

//!强制同步数据库(创建数据表)
/* Topic.sync({
  force: true, //? 将创建表, 如果表已经存在, 则将其首先删除
}); */

module.exports = Topic;
